package com.wcl.demo.ui.activity;

import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

import com.easemob.chat.EMChatManager;
import com.easemob.chat.EMGroupManager;
import com.wcl.demo.R;
import com.wcl.demo.utils.ActivityUtils;
import com.wcl.demo.view.CustomGridLayout;
import com.wcl.demo.view.CustomToast;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by dllo on 15/11/17.
 */

public class LoginPageActivity extends BaseActivity {

    /**
     * 透明动画
     **/
    Animation mAnimation = null;
    View view;
    ImageView alpha_image;
    private Runnable r = new Runnable() {
        @Override
        public void run() {
            int randomNumber = (int) (Math.random() * 15);
            //  image_item.setImageResource(srcs[i-1]);
            //  image_item.startAnimation(mAnimation);
            view = custom_gridLayout.getChildAt(randomNumber);
            alpha_image= (ImageView) view.findViewById(R.id.alpha_image);
            alpha_image.startAnimation(mAnimation);
           // view.clearAnimation();
            handler.postDelayed(r, 2000);
        }
    };
    private Handler handler;

    @Bind(R.id.custom_gridLayout)
    CustomGridLayout custom_gridLayout;

    private int[] srcs = {R.mipmap.ic_welcome_photo_1, R.mipmap.ic_welcome_photo_2,
            R.mipmap.ic_welcome_photo_3, R.mipmap.ic_welcome_photo_4,
            R.mipmap.ic_welcome_photo_5, R.mipmap.ic_welcome_photo_6,
            R.mipmap.ic_welcome_photo_7, R.mipmap.ic_welcome_photo_8,
            R.mipmap.ic_welcome_photo_9, R.mipmap.ic_welcome_photo_10,
            R.mipmap.ic_welcome_photo_11, R.mipmap.ic_welcome_photo_12,
            R.mipmap.ic_welcome_photo_13, R.mipmap.ic_welcome_photo_14,
            R.mipmap.ic_welcome_photo_15};

    @Override
    protected int getLayout() {
        return R.layout.activity_login_page;
    }

    @Override
    protected void initView() {
        handler = new Handler();
        mAnimation = AnimationUtils.loadAnimation(this, R.anim.anim_alpha);
    }

    @Override
    protected void initData() {
        custom_gridLayout.setGridAdapter(new CustomGridLayout.GridAdatper() {
            @Override
            public View getView(int index) {
                View view = LayoutInflater.from(LoginPageActivity.this).inflate(R.layout.activity_login_page_item, null);
                ImageView image_item = (ImageView) view.findViewById(R.id.login_image_item);
                image_item.setImageResource(srcs[index]);
                return view;
            }
            @Override
            public int getCount() {
                return srcs.length;
            }
        });

        handler.postDelayed(r, 0);
    }

    @OnClick(R.id.loginPage_register)
    void loginPage_register() {
        ActivityUtils.startToActivity(this, RegisterActivity.class);
        CustomToast.toastShow(this, "点击了注册");
    }

    @OnClick(R.id.loginPage_login)
    void loginPage_login() {
        ActivityUtils.startToActivity(this, LoginActivity.class);
        CustomToast.toastShow(this, "点击了登录");
    }
}
